<template>
	<view>
		<navbar name="个人设置"></navbar>
		<view class="w750bgf">
			<block v-for="(item,idx) in userList" :key="idx">
				<view class="user-view" @tap="navtab(item,idx)">
					<view class="user-title">
						{{item.title}}
					</view>
					<image v-if="idx == 0" class="setting-user-image" :src="result.avatarUrl" mode="头像"></image>
				</view>
				<u-line v-show="userList.length -1 !=idx" />
			</block>
		</view>
		<button @tap="signOut" class="quit" type="default">退出登录</button>
	</view>
</template>

<script>

import uLine from "@/uview-ui/components/u-line/u-line.vue"

	export default {
		components: {
			uLine,
		},
		data() {
			return {
				result: '',
				userList: [{
						title: '账户设置',
						image: 'https://cdn.uviewui.com/uview/swiper/3.jpg'
					},
					{
						title: '权限设置',
					},
					{
						title: '用户服务协议',
					},
					{
						title: '隐私政策条款',
					},
					{
						title: '关于我们',
					}
				],
			}
		},
		onLoad() {
			this.getBaseUserInfo()
		},
		methods: {
			signOut(){
				uni.showToast({
					title: '退出成功',
					// icon: 'none',
					// position: 'bottom',
					duration: 1500
				})
				global.token = ''
				global.userInfo = null
				let loginKey = global.IS_DEV?'USER_TOKEN_BSY_T':'USER_TOKEN_BSY_Z'

				uni.removeStorageSync(loginKey)
				uni.removeStorageSync(global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z')
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/tab/home',
					});
				}, 1500);
			},
			getBaseUserInfo() {
				let _this = this;
				this.$loginl.get(global.apiUrls.getBaseUserInfo + '?userId=' + uni.getStorageSync(
						global.IS_DEV?'USER_DATA_BSY_T':'USER_DATA_BSY_Z').userId, {})
					.then(res => {
						if (res.data.code == 1000) {
							let result = res.data.result;
							_this.result = result;
						}
					}).catch(err => {})
			},
			navtab(item, idx) {
				if (idx == 0) {
					uni.navigateTo({
						url: '/pagesMy/my/settingUp/accountsetting'
					})
				} else if (idx == 1) {
					uni.navigateTo({
						url: '/pagesMy/my/settingUp/jurisdiction'
					})
				} else if (idx == 2) {
					uni.navigateTo({
						url: '/pagesMy/my/settingUp/protocol?name=用户服务协议'
					})
				} else if (idx == 3) {
					uni.navigateTo({
						url: '/pagesMy/my/settingUp/protocol?name=隐私政策条款'
					})
				} else {
					uni.navigateTo({
						url: '/pagesMy/my/settingUp/AboutUs'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	@import "./base.scss"
</style>
